import frida
import os,sys

def on_message(message, data):
    if message['type'] == 'send':
        print(message['payload'])
    elif message['type'] == 'error':
        print(message['stack'])

def adbforward():
    os.system("adb forward tcp:8888 tcp:8888")
    # os.system("adb forward tcp:27043 tcp:27043")


with open("dexdump.js",'r',encoding='utf8') as f:
    test_js=f.read()
adbforward()
host='127.0.0.1:8888'
manager = frida.get_device_manager()
device=manager.add_remote_device(host)

# process = frida.get_usb_device(-1).attach('com.qiyi.video')
process = device.attach('com.qiyi.video')
script = process.create_script(test_js)  # test 刚才定义得js字符串
script.on('message',on_message)
script.load()
# sys.stdin.read()
'''
# 脱壳
res = script.exports.secdex("s")

for m in res:
    print("sss:\t",m.get('addr'),m.get('size'))
    content = script.exports.readm(m.get('addr'),m.get('size'))
    with open("./"+str(m.get('addr'))+"_"+str(m.get('size'))+".dex",'wb') as f:
        f.write(content)

'''


script.exports.test()
